package 滑动窗口;

public class test1 {
    /**
     * 滑动窗口:
     * 1. 用left和right作为窗口的左右端点,中间表示窗口区间
     * 2. 进窗口的条件,出窗口的条件
     */
    public int minSubArrayLen(int target, int[] nums){
        int n = nums.length,sum = 0,len = Integer.MAX_VALUE;
        for (int left=0,right=0; right < n; right++) {
            sum+=nums[right];
            while (sum>=target){
                len = Math.min(len,right-left+1);
                sum -= nums[left];
                left++;
            }
        }
        return len==Integer.MAX_VALUE?0:len;
    }
}
